﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using LotroTweeter.Data;

namespace LotroTweeter.Engine
{
    public class DataEngine
    {
        private KinRoster oldRoster;
        private KinRoster newRoster;

        public DataEngine(XElement oldRoster, XElement newRoster)
        {
            var converter = new DataConverter();
            this.oldRoster = converter.ConvertKinRoster(oldRoster);
            this.newRoster = converter.ConvertKinRoster(newRoster);
        }

        public IEnumerable<KinMember> GetNewMembers()
        {
            var currentMembers = from m in newRoster.Members
                                 where !oldRoster.Members.Any(o => o.Name == m.Name)
                                 select m;
            return currentMembers.AsEnumerable();
        }

        public IEnumerable<KinMember> GetLevelUps()
        {
            var currentMembers = from m in newRoster.Members
                                 where oldRoster.Members.Any(o => o.Name == m.Name && o.Level != m.Level)
                                 select m;
            return currentMembers.AsEnumerable();
        }
    }
}
